/*************************************************************************
	> File Name: large_file.c
	> Author: Angel Criss
	> Mail: abbytsing@gmail.com 
	> Created Time: 五  3/28 21:23:35 2014
 ************************************************************************/

#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/uio.h>
int main(int argc, char *argv[])
{
    if(argc!=3)
    {
    printf("run this by ./a.out number filename  \n");
    exit(0);
    }
    
    int fileo , filew;
    long long len;
    len=atoll(argv[1]);
    fileo=open(argv[2],O_RDWR|O_CREAT,00644);//O_APPEND参数出现的话，下面的lseek就会失效
    if(fileo==-1)
        perror("cannot open or creat file");
    else
        printf("opened/ created source file\n");
    if(lseek(fileo,(off_t)len,SEEK_SET)==-1)
        perror("lseek failed");
    else
        filew=write(fileo,"the end",7);
            if(filew==-1)
                perror("failed to write");
            else
                printf("write succeed\n");
    if((close(fileo))==-1)
        perror("failed to close");
    else
        printf("All Done !\n\n");
}
